[sc-208287] Add JWT and security classes to SDK#112
Merged
AshleyDawson merged 1 commit intomainfrom Dec 16, 2025
Merged
Conversation
Reviewer's GuideAdds a security abstraction to the Deskpro SDK client, exposing JWT minting via a new Security API that delegates to parent window methods when available and falls back to safe no-op defaults. Sequence diagram for JWT minting via DeskproClient security APIsequenceDiagram
actor IntegrationApp
participant DeskproClient
participant Security
participant JWT
participant ParentWindow
IntegrationApp->>DeskproClient: security()
DeskproClient-->>IntegrationApp: Security
IntegrationApp->>Security: jwt(strategyName)
Security-->>IntegrationApp: JWT
IntegrationApp->>JWT: mint(context)
JWT->>DeskproClient: securityJwtMint(strategyName, context)
alt parent _securityJwtMint available
DeskproClient->>ParentWindow: _securityJwtMint(strategyName, context)
ParentWindow-->>DeskproClient: JwtMintResult
else no parent _securityJwtMint
DeskproClient-->>DeskproClient: use default securityJwtMint implementation
end
DeskproClient-->>JWT: JwtMintResult
JWT-->>IntegrationApp: JwtMintResult
Class diagram for new DeskproClient security and JWT abstractionsclassDiagram
class IDeskproClient {
<<interface>>
+securityJwtMint(strategyName: string, context: Context) JwtMintResult
+security() ISecurity
}
class DeskproClient {
+securityJwtMint(strategyName: string, context: Context) JwtMintResult
+security() ISecurity
}
class CoreCallSender {
<<interface>>
+_securityJwtMint(strategyName: string, context: Context) JwtMintResult
}
class ISecurity {
<<interface>>
+jwt(strategyName: string) IJWT
}
class Security {
-client IDeskproClient
+Security(client: IDeskproClient)
+jwt(strategyName: string) IJWT
}
class IJWT {
<<interface>>
+mint(context: Context) JwtMintResult
}
class JWT {
-client IDeskproClient
-strategyName string
+JWT(client: IDeskproClient, strategyName: string)
+mint(context: Context) JwtMintResult
}
class JwtMintResult {
+token string
+expiresAt string
}
DeskproClient ..|> IDeskproClient
Security ..|> ISecurity
JWT ..|> IJWT
DeskproClient --> Security : creates
Security --> JWT : creates
DeskproClient ..> CoreCallSender : delegates _securityJwtMint
DeskproClient --> JwtMintResult
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
AshleyDawson
approved these changes
Dec 4, 2025
5286116 to
f3e0331
Compare
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- The default implementation of
securityJwtMintin theDeskproClientconstructor returns a string, which does not match the declaredPromise<JwtMintResult>type; consider either returning aJwtMintResultstub or throwing an explicit error for unsupported environments. - The
securityJwtMintwrapper insideregisterParentMethodswraps the call in atry/catchthat simply rethrows the error; you can remove thetry/catchand directly returnparent._securityJwtMint(strategyName, context)for simpler code.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The default implementation of `securityJwtMint` in the `DeskproClient` constructor returns a string, which does not match the declared `Promise<JwtMintResult>` type; consider either returning a `JwtMintResult` stub or throwing an explicit error for unsupported environments.
- The `securityJwtMint` wrapper inside `registerParentMethods` wraps the call in a `try/catch` that simply rethrows the error; you can remove the `try/catch` and directly return `parent._securityJwtMint(strategyName, context)` for simpler code.
## Individual Comments
### Comment 1
<location> `src/client/client.ts:251` </location>
<code_context>
this.sendDeskproUIMessage = async () => { };
+ this.securityJwtMint = async () => "";
+
if (this.options.runAfterPageLoad) {
</code_context>
<issue_to_address>
**issue (bug_risk):** Default `securityJwtMint` implementation returns a string, which is inconsistent with the declared `Promise<JwtMintResult>` type.
This implementation should return a `JwtMintResult`-shaped object rather than a string to match the `Promise<JwtMintResult>` signature and avoid type or runtime mismatches for callers expecting `{ token, expiresAt }`.
</issue_to_address>
### Comment 2
<location> `src/client/client.ts:438-439` </location>
<code_context>
const result = await parent._securityJwtMint(strategyName, context);
return result;
</code_context>
<issue_to_address>
**suggestion (code-quality):** Inline variable that is immediately returned ([`inline-immediately-returned-variable`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/TypeScript/Default-Rules/inline-immediately-returned-variable))
```suggestion
return await parent._securityJwtMint(strategyName, context);
```
<br/><details><summary>Explanation</summary>Something that we often see in people's code is assigning to a result variable
and then immediately returning it.
Returning the result directly shortens the code and removes an unnecessary
variable, reducing the mental load of reading the function.
Where intermediate variables can be useful is if they then get used as a
parameter or a condition, and the name can act like a comment on what the
variable represents. In the case where you're returning it from a function, the
function name is there to tell you what the result is, so the variable name
is unnecessary.
</details>
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
f3e0331 to
e440dfc
Compare
AshleyDawson
approved these changes
Dec 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Introduce SDK support for security-related operations centered around JWT minting.
New Features:
Enhancements: